<?php
namespace app\index\controller;
use think\captcha\Captcha;
use think\Db;
use think\facade\Session; //Session
use think\facade\Cookie; // cookie

class User extends \think\Controller
{
    public function login()
    {
        //登录
            if ($_POST) {
                //验证用户名和密码
                $user_name = $this->request->post('user_name');
                $user_pwd = md5($this->request->post('user_pwd'));
                $user = Db::name('user')->where("user_name='$user_name' AND user_pwd='$user_pwd'")->find();
                if ($user) {
                    //验证通过
                    Cookie::set('user_name', $user_name, 3600); //有效期3600秒
                    //设置 session
                    Session::set('is_login', '1');
                    $this->success('登录成功', '/index/index/home');
                } else {
                    $this->error('用户名或密码输入有误');
                }
            }
            return $this->fetch();
        }
}
